#include<bits/stdc++.h>

#define rp(i,n) for(long long i=0;i<n;++i)
#define BEGIN 0
#define END 1

using namespace std;

struct node
{
	int type,c,time,index;
};

bool cmp(node a, node b){
	if(a.time != b.time)
		return a.time < b.time;
	else
		return a.type < b.type;
}

std::vector<node> v;

int main(){
	int N,C;scanf("%d%d", &N,&C);
	v.resize(N*2);
	rp(i,N){
		int a,b,c;scanf("%d%d%d", &a,&b,&c);
		v[i*2].type = BEGIN; v[i*2+1].type = END;
		v[i*2].c = v[i*2+1].c = c;
		v[i*2].time = a; v[i*2+1].time = b;
		v[i*2].index = v[i*2+1].index = i;
	}
	sort(v.begin(),v.end(),cmp);

	long long ans = 0;
	int cnt = 0;
	long long servicePrice = 0;
	long long distance = 0;
	while(cnt < N*2){
		if(cnt>0)distance = v[cnt].time - v[cnt -1].time;
		// printf("ans = %lld, distance = %lld, servicePrice = %lld\n", ans, distance,servicePrice);
		if(v[cnt].type == BEGIN){
			if(distance > 0){
				ans += min(servicePrice,(long long)C) * (distance);
			}
			servicePrice += v[cnt].c;
		}else{
			ans += min(servicePrice,(long long)C) * (distance + 1);
			servicePrice -= v[cnt].c;
			while(cnt + 1 < N*2 && v[cnt + 1].time == v[cnt].time){
				++cnt;
				servicePrice -= v[cnt].c;
			}
		}
		++cnt;
		distance = 0;
		// printf("ans = %lld, servicePrice = %lld\n", ans, servicePrice);
	}

	printf("%lld\n", ans);
	
	return 0;
}